package com.glela.goods.service.impl.customer;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSONObject;
import com.glela.cache.redis.RedisUtil;
import com.glela.common.util.JsonUtil;
import com.glela.common.util.StringUtil;
import com.glela.goods.model.vo.goods.GoodsVo;
import com.glela.goods.service.GoodsService;
import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.response.ResponseBaseModel;

public class GoodsCustomer {
	@Autowired
	private GoodsService goodsService;
	
	@Autowired
	private RedisUtil redisUtil;

	public RedisUtil getRedisUtil() {
		return redisUtil;
	}

	public void setRedisUtil(RedisUtil redisUtil) {
		this.redisUtil = redisUtil;
	}
	
	
	public void onMessage(Map<String,Object> map) {
		try {
			String redisKey = map.get("redisKey").toString();
			long goodsid = Long.valueOf(map.get("goodsid").toString());
			long productId = Long.valueOf(map.get("productId").toString());
			int limitTimeSaleId = Integer.valueOf(map.get("limitTimeSaleId").toString());
			long userId = Long.valueOf(map.get("userId").toString());
			int storeUserId = Integer.valueOf(map.get("storeUserId").toString());
			String from = map.get("from").toString();
			
			String keyEffectiveTime = redisUtil.get(redisKey+"-effectivetime");
			if (StringUtil.isEmpty(keyEffectiveTime)) {
				redisUtil.setex(redisKey+"-effectivetime", 30, redisKey);
				
				GoodsVo goodsVo = this.goodsService.getGoodsInfoById(goodsid,productId,limitTimeSaleId,userId,storeUserId,from);
				String result = "";
				if (goodsVo != null) {
					result = JSONObject.toJSONString(goodsVo);
				}
				// 缓存商品详情页对象(有效期1天)
				redisUtil.setex(redisKey, 86400,result);
				// 缓存商品详情页有效时间
				
			}
		} catch (Exception e) {
			
		}
	}

	public GoodsService getGoodsService() {
		return goodsService;
	}

	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	
	
	
	
	
}
